#!/bin/bash

flink=/opt/module/flink-yarn/bin/flink
realtime_jar=/opt/module/gmall20210623/gmall-realtime-1.0-SNAPSHOT.jar
apps=(
  com.atguigu.gmall.realtime.app.dwd.DwdLogApp
#  com.atguigu.gmall.realtime.app.dwd.DwdDbApp
  com.atguigu.gmall.realtime.app.dwm.DwmUvApp
  com.atguigu.gmall.realtime.app.dwm.DwmUserJumpDetailApp
# com.atguigu.gmall.realtime.app.dwm.DwmOrderWide
# com.atguigu.gmall.realtime.app.dwm.DwmOrderWide_Cache
# com.atguigu.gmall.realtime.app.dwm.DwmOrderWide_Cache_Async
# com.atguigu.gmall.realtime.app.dwm.DwmPaymentWide
com.atguigu.gmall.realtime.app.dws.DwsVisitorStatesApp
)
# 找到已经启动的app
running_apps=$(${flink} list -r 2>/dev/null | awk '/RUNNING/ {print $(NF-1)}')

for app in ${apps[*]}; do
  # 判断app是否已经启动
  job_name=$(echo ${app} | awk -F. '{print $NF}')
  # shellcheck disable=SC2199
  if [[ "${running_apps[@]}" =~ $job_name ]]; then
    echo "$job_name 已经启动，无需重复启动"
  else
    echo ">>> 开始启动 $job_name <<<"
    ${flink} run -d -c ${app} ${realtime_jar}
  fi
done
